import { defineStore } from "pinia";
import { listFriends, addFriend, removeFriend, findFriends } from "@/api/friend";

export const useFriendStore = defineStore("friend", {
  // 开启数据缓存
  persist: {
    enabled: true,
  },

  state: () => {
    return {
      friendList: []
    }
  },
  actions: {
    getList() {
      return new Promise((resolve, reject) => {
        listFriends().then((res) => {
          if (res.code !== 200) {
            reject(res.message)
            return
          }
          this.friendList = res.data
          resolve(res.data)
        })
      })
    }
  },
});
